<?php

namespace Frieza\Modules\Position\Controllers;

use Doraemon\pockets\constInterface\AppFunction;
use Doraemon\service\position\AdmExtOperationModule;
use Doraemon\tools\ImgUrl;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;

class HomeRecommendGuideController extends BaseController
{
    use BaseTrait;

    public function saveModule(Request $request, $baseInfoId)
    {
        $data = [
            'position_id' => $this->positionId,
            'position_base_info_id' => $baseInfoId,
            'title' => $request->input('title', ''),
            'subtitle' => $request->input('subtitle', ''),
            'icon' => $request->input('icon', ''),
            'button_title' => $request->input('button_title', ''),
            'bgcolor' => $request->input('bgcolor', ''),
            'apply' => $request->input('apply', ''),
            'days' => $request->input('days', ''),
        ];
        AdmExtOperationModule::addPositionGuideTool($data);
    }

    public function beforeLinkForm(Form $form)
    {
        $form->text('title', '主标题');
        $form->text('subtitle', '副标题');
        $form->text('button_title', '按钮文案');
        $form->imgUpload('icon', 'icon', true, ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
        $form->color('bgcolor', '背景色');
    }

    public function beforeProfileForm(Form $form)
    {
        $form->select('apply', '功能列表')->options(AppFunction::FUNCTION_MAP);
        $form->number('days', '未使用天数')->placeholder('天数')->default(0)->help('0为不限制');
    }

    public function delModule($id)
    {
        AdmExtOperationModule::delPositionGuideTool($id);
    }

    public function extendList(Grid $grid)
    {
        $grid->column('ext->title', '主标题');
    }

}
